var sorted = require('is-sorted')


var defaultComparator = function(a, b) {
	return a - b
}

function arraySorted(arr, comparator) {
	if(!Array.isArray(arr)) {
		throw new TypeError('Excepted Array, got ' + (typeof arr))
	}
	comparator = comparator || defaultComparator
	for (var i = 0; i < arr.length-1; i++) {
		if(comparator(arr[i], arr[i+1]) > 0) {
			return false 
		}
	}

	return true
}


console.group('is-sorted');

console.log(sorted([1, 2, 3]))
// => true

console.log(sorted([3, 1, 2]))
// => false

// supports custom comparators
console.log(sorted([3, 2, 1], function (a, b) { return b - a }))
// => true

console.groupEnd()

console.log('-------------------------------------------\n')


console.group('自定义');
console.log(arraySorted([1, 2, 3]))
// => true

console.log(arraySorted([3, 1, 2]))
// => false

// supports custom comparators
console.log(arraySorted([3, 2, 1], function (a, b) { return b - a }))
// => true
console.groupEnd()
